package calculator;

/**
 * 运算器工厂.
 *
 * @author GongXincheng
 * @since 2019-09-13 14:05
 */
public class OperationFactory {

    /**
     * 根据 运算符字符串 获取运算符对象.
     *
     * @param operation 运算符字符串
     * @return 运算符对象
     */
    public static AbstractOperation getOperation(String operation) {
        AbstractOperation result;
        switch (operation) {
            case "+":
                result = new OperationAdd();
                break;
            case "-":
                result = new OperationSub();
                break;
            case "*":
                result = new OperationMul();
                break;
            case "/":
                result = new OperationDiv();
                break;
            default:
                throw new RuntimeException("不支持该运算符");
        }
        return result;
    }

}
